# 转换为int - int(x)
# str转int —— 纯数字字符串才可以转换
s = "2024"
n = int(s)
print(type(n))
s1 = "2.2"
print(int(s1))
s2 = "123aas"
print(int(s2))
# float转int
s1 = 5.22
print(int(s1))
# bool转int
print(int(True), int(False))



# 转换为浮点数float - float(x)
# str转float
print(float("2024"))
# print(float("2024aa"))
# int转float
f = 2024
print(float(f))
# bool转float
print(float(True), float(False))



# 转换为布尔bool - bool(x)
# str转bool
print(bool("123aa"))
print(bool(""))
# int转bool
print(bool(1))
print(bool(0))
# float转bool
print(bool(2.0))
print(bool(0.0))

print(bool(None))



# 转换为字符串 - str(x)
# int转str
print(str(1024))
# float转str
print(str(5.20))
# bool转str
print(str(True))  # "True"
print(str(False))  # "False"



# 进制转换
s = '1010'
print(int(s, 2))  # 将二进制的s转换为int
s = '1a'
print(int(s, 16))



# 小整数地址问题
# Python中-5至256存在缓存池中，Pycharm进行了进一步优化
# 可以使用id()测试
a = 3
print(id(a))
b = 3
print(id(b))